﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MoLingsArmory.Content.Projectiles;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace MoLingsArmory.Content.Items.Weapons.Magic
{
    public class NebularStaff : ModItem
    {
        public override void SetStaticDefaults()
        {
            Item.staff[Item.type] = true;
        }

        public override void SetDefaults()
        {
            Item.damage = 220;
            Item.DamageType = DamageClass.Magic;
            Item.width = 48;
            Item.height = 48;
            Item.useAnimation = 20;
            Item.useTime = 20;
            Item.mana = 14;
            Item.useStyle = ItemUseStyleID.Shoot;
            Item.noMelee = true;
            Item.knockBack = 8f;
            Item.value = Item.sellPrice(gold: 10);
            Item.rare = ItemRarityID.Red;
            Item.channel = true;
            Item.autoReuse = true;
            Item.shoot = ModContent.ProjectileType<NebularStaffHold>();
            Item.shootSpeed = 30f;
        }
        public override bool CanUseItem(Player player)
        {
            if (player.ownedProjectileCounts[ModContent.ProjectileType<NebularStaffHold>()] > 0)
            {
                return false;
            }
            return base.CanUseItem(player);
        }

        public override void AddRecipes()
        {
            Recipe recipe = CreateRecipe();
            recipe.AddIngredient(ItemID.FragmentNebula, 18);
            recipe.AddTile(TileID.LunarCraftingStation);
            recipe.Register();
        }
        public override void PostDrawInWorld(SpriteBatch spriteBatch, Color lightColor, Color alphaColor, float rotation, float scale, int whoAmI)
        {
            Texture2D glowTexture = ModContent.Request<Texture2D>("MoLingsArmory/Content/Items/Weapons/Magic/NebularStaff_Glow").Value;
            spriteBatch.Draw(glowTexture, Item.Center - Main.screenPosition, null, Color.White, rotation, glowTexture.Size() * 0.5f, scale, SpriteEffects.None, 0f);
        }
    }
}
